package com.wechat.service.account.config;

import com.wechat.service.account.service.HandleMenuEventService;
import com.wechat.service.account.service.impl.DefaultHandleMenuEventServiceImpl;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;

/**
 * @Author yanggld
 * @Date 2019/7/10-16:59
 * @Description
 */

@Configuration
public class BeanConfig {

	@Bean
	@ConditionalOnMissingBean(RestTemplate.class)
	public RestTemplate restTemplate() {
		SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
		factory.setReadTimeout(5000);//ms
		factory.setConnectTimeout(15000);//ms
		return new RestTemplate(factory);
	}

	@Bean
	@ConditionalOnMissingBean(HandleMenuEventService.class)
	public HandleMenuEventService handleMenuEventService() {
		return new DefaultHandleMenuEventServiceImpl();
	}
}